home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Wizard Question
- Date: Tue, 23 Jan 1996 22:11:24 GMT
- Organization: Netcom
- Message-ID: <31055b5f.172082688@nntp.ix.netcom.com>
- References: <310533BD.847@jsp.com>
- NNTP-Posting-Host: ix-dc18-03.ix.netcom.com
- X-NETCOM-Date: Tue Jan 23 2:10:43 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
-
- Jeff PErry <jeff@jsp.com> wrote:
-
- > So, you think you're a C++ Wizard, eh? Good. Then could you
- > please comment on the following few statements:
- >
- > throw "This is an exception thrown deep in the call stack";
- >
- > ...
- >
- > catch (const char *E)
- > {
- > // Do something with E
- > }
- >
- > This is a practice that I have used before, and only recently
- > did it occur to me that it might not be such a great idea to be
- > throwing a pointer to something on the stack. On the other
- > hand, it is a constant, so it has to live somewhere permanently.
- >
- > The question is: Is it safe to assume that the string to which E
- > points will be valid in my catch block, even though the call
- > stack has been unwound?
-
- A string literal has static storage duration. The string literal
- remains in existence until the program ends.
-
- In any case, you are throwing the exception with an array object and a
- copy of the object must be made and preserved until the exception is
- handled (unless, of course, the compiler can determine that this is
- unnecessary).
-
- In short, this is safe.
-
- Michael M Rubenstein
-